#include "common.h"

int totalFruit(vector<int>&fruits)
{
	int ans;
	int n = fruits.size();
	int left = 0;
	int right = 0;
	vector<int>flg(n, 0);
	int m = 0;
	while (right < n)
	{
		if (flg[fruits[right++]]++ == 0) m++;
		while (m > 2)
		{
			if (--flg[fruits[left++]] == 0) m--;
		}
		ans = max(ans, right - left);
	}
	return ans;
}
